﻿using System;
using System.Collections.Generic;
using System.Linq;
using DataGeneration.Makers;

namespace DataGeneration.Helpers
{
    public class DataHelper
    {
        public static Dictionary<string, string> Capitals = new Dictionary<string, string>
                                                                {
                                                                    {"France", "Paris"},
                                                                    {"Peru", "Lima"},
                                                                    {"Colombia", "Bogotá"},
                                                                    {"Iraq", "Baghdad"},
                                                                    {"Rwanda", "Kigali"},
                                                                    {"Japan", "Tokyo"},
                                                                    {"the USA", "Washington, D.C."},
                                                                    {"Canada", "Ottawa"},
                                                                    {"Australia", "Canberra"},
                                                                    {"Argentina", "Buenos Aires"},
                                                                    {"Russia", "Moscow"},
                                                                    {"Austria", "Vienna"},
                                                                    {"Brazil", "Brasília"},
                                                                    {"Cambodia", "Phnom Penh"},
                                                                    {"Chile", "Santiago"},
                                                                    {"Denmark", "Copenhagen"},
                                                                    {"Ecuador", "Quito"},
                                                                    {"Egypt", "Cairo"},
                                                                    {"Estonia", "Tallinn"},
                                                                    {"Greece", "Athens"},
                                                                    {"Finland", "Helsinki"},
                                                                    {"Iceland", "Reykjavík"},
                                                                    {"India", "New Delhi"},
                                                                    {"Iran", "Tehran"},
                                                                    {"Libya", "Tripoli"},
                                                                    {"Mali", "Bamako"},
                                                                    {"Pakistan", "Islamabad"},
                                                                    {"China", "Beijing"},
                                                                    {"Indonesia", "Jakarta"},
                                                                    {"Bangladesh", "Dhaka"},
                                                                    {"Nigeria", "Abuja"},
                                                                    {"South Korea", "Seoul"},
                                                                    {"Mexico", "Mexico City"},
                                                                    {"the United Kingdom", "London"},
                                                                };

        public static Dictionary<string, string> Books = new Dictionary<string, string>
                                                             {
                                                                 {"Don Quixote", "Miguel de Cervantes"},
                                                                 {"War and Peace", "Leo Tolstoy"},
                                                                 {"Ulysses", "James Joyce"},
                                                                 {"In Search of Lost Time", "Marcel Proust"},
                                                                 {"The Brothers Karamazov", "Feodor Dostoevsky"},
                                                                 {"Moby-Dick", "Herman Melville"},
                                                                 {"Madame Bovary", "Gustave Flaubert"},
                                                                 {"The Magic Mountain", "Thomas Mann"},
                                                                 {"The Tale of Genji", "Murasaki Shikibu"},
                                                                 {"Emma", "Jane Austen"},
                                                                 {"Bleak House", "Charles Dickens"},
                                                                 {"Anna Karenina", "Leo Tolstoy"},
                                                                 {"Adventures of Huckleberry Finn", "Mark Twain"},
                                                                 {"Tom Jones", "Henry Fielding"},
                                                                 {"Great Expectations", "Charles Dickens"},
                                                                 {"Absalom, Absalom!", "William Faulkner"},
                                                                 {"The Ambassadors", "Henry James"},
                                                                 {
                                                                     "One Hundred Years of Solitude",
                                                                     "Gabriel Garcia Marquez"
                                                                     },
                                                                 {"The Great Gatsby", "F. Scott Fitzgerald"},
                                                                 {"To The Lighthouse", "Virginia Woolf"},
                                                                 {"Crime and Punishment", "Feodor Dostoevsky"},
                                                                 {"The Sound and the Fury", "William Faulkner"},
                                                                 {"Vanity Fair", "William Makepeace Thackeray"},
                                                                 {"Invisible Man", "Ralph Ellison"},
                                                                 {"Finnegans Wake", "James Joyce"},
                                                                 {"The Man Without Qualities", "Robert Musil"},
                                                                 {"The Portrait of a Lady", "Henry James"},
                                                                 {"Women in Love", "D. H. Lawrence"},
                                                                 {"The Red and the Black", "Stendhal"},
                                                                 {"Tristram Shandy", "Laurence Sterne"},
                                                                 {"Dead Souls", "Nikolai Gogol"},
                                                                 {"Tess of the D'Urbervilles", "Thomas Hardy"},
                                                                 {"Buddenbrooks", "Thomas Mann"},
                                                                 {"Le Pere Goriot", "Honore de Balzac"},
                                                                 {
                                                                     "A Portrait of the Artist as a Young Man",
                                                                     "James Joyce"
                                                                     },
                                                                 {"Wuthering Heights", "Emily Bronte"},
                                                                 {"The Tin Drum", "Gunter Grass"},
                                                                 {"Pride and Prejudice", "Jane Austen"},
                                                                 {"The Scarlet Letter", "Nathaniel Hawthorne"},
                                                                 {"Beloved", "Toni Morrison"},
                                                                 {"An American Tragedy", "Theodore Dreiser"},
                                                                 {"Lolita", "Vladimir Nabokov"},
                                                                 {"The Golden Notebook", "Doris Lessing"},
                                                                 {"Clarissa", "Samuel Richardson"},
                                                                 {"Dream of the Red Chamber", "Cao Xueqin"},
                                                                 {"The Trial", "Franz Kafka"},
                                                                 {"Jane Eyre", "Charlotte Bronte"},
                                                                 {"The Red Badge of Courage", "Stephen Crane"},
                                                                 {"The Grapes of Wrath", "John Steinbeck"},
                                                                 {"Things Fall Apart", "Chinue Achebe"},
                                                                 {"The Princess of Cleves", "Madame de Lafayette"},
                                                                 {"The Stranger", "Albert Camus"},
                                                                 {"My Antonia", "Willa Cather"},
                                                                 {"The Counterfeiters", "Andre Gide"},
                                                                 {"The Age of Innocence", "Edith Wharton"},
                                                                 {"The Awakening", "Kate Chopin"},
                                                                 {"A Passage to India", "E. M. Forster"},
                                                                 {"Germinal", "Emile Zola"},
                                                                 {"Call It Sleep", "Henry Roth"},
                                                                 {"U.S.A. Trilogy", "John Dos Passos"},
                                                                 {"Hunger", "Knut Hamsun"},
                                                                 {"Berlin Alexanderplatz", "Alfred Doblin"},
                                                                 {"Cities of Salt", "'Abd al-Rahman Munif"},
                                                                 {"The Death of Artemio Cruz", "Carlos Fuentes"},
                                                                 {"A Farewell to Arms", "Ernest Hemingway"},
                                                                 {"Brideshead Revisited", "Evelyn Waugh"},
                                                                 {"The Last Chronicle of Barset", "Anthony Trollope"},
                                                                 {"The Pickwick Papers", "Charles Dickens"},
                                                                 {"Robinson Crusoe", "Daniel Defoe"},
                                                                 {
                                                                     "The Sorrows of Young Werther",
                                                                     "Johann Wolfgang von Goethe"
                                                                     },
                                                                 {"Oblomov", "Ivan Goncharov"},
                                                                 {"Their Eyes Were Watching God", "Zora Neale Hurston"},
                                                                 {"Waverley", "Sir Walter Scott"},
                                                                 {"Snow Country", "Kawabata Yasunari"},
                                                                 {"Nineteen Eighty-Four", "George Orwell"},
                                                                 {"The Betrothed", "Alessandro Manzoni"},
                                                                 {"The Last of the Mohicans", "James Fenimore Cooper"},
                                                                 {"Les Miserables", "Victor Hugo"},
                                                                 {"Frankenstein", "Mary Shelley"},
                                                                 {"The Leopard", "Giuseppe Tomasi di Lampedusa"},
                                                                 {"The Woman in White", "Wilkie Collins"},
                                                                 {"The Good Soldier Svejk", "Jaroslav Hasek"},
                                                                 {"Dracula", "Bram Stoker"},
                                                                 {"Gone with the Wind", "Margaret Mitchell"},
                                                             };

        public static Dictionary<string, string> Albums = new Dictionary<string, string>
                                                              {
                                                                  {
                                                                      "Sgt Pepper's Lonely Hearts Club Band", "The Beatles"
                                                                      },
                                                                  {"Pet Sounds", "The Beach Boys"},
                                                                  {"What's Going On", "Marvin Gaye"},
                                                                  {"Dark Side Of The Moon", "Pink Floyd"},
                                                                  {"Revolver", "The Beatles"},
                                                                  {"Live at the Apollo", "James Brown"},
                                                                  {"Highway 61 Revisited", "Bob Dylan"},
                                                                  {"Thriller", "Michael Jackson"},
                                                                  {"Are You Experienced?", "Jimi Hendrix"},
                                                                  {"Rubber Soul", "The Beatles"},
                                                                  {
                                                                      "It Takes A Nation Of Millions To Hold Us Back",
                                                                      "Public Enemy"
                                                                      },
                                                                  {"Nevermind", "Nirvana"},
                                                                  {"Elvis Presley", "Elvis Presley"},
                                                                  {"Born To Run", "Bruce Springsteen"},
                                                                  {"Exile On Main Street", "The Rolling Stones"},
                                                                  {"Blonde On Blonde", "Bob Dylan"},
                                                                  {"Innervisions", "Stevie Wonder"},
                                                                  {"London Calling", "The Clash"},
                                                                  {"Abbey Road", "The Beatles"},
                                                                  {"Purple Rain", "Prince"},
                                                                  {"Who's Next", "The Who"},
                                                                  {"Led Zeppelin II", "Led Zeppelin"},
                                                                  {"Songs In The Key Of Life", "Stevie Wonder"},
                                                                  {"The Joshua Tree", "U2"},
                                                                  {"Rumours", "Fleetwood Mac"},
                                                                  {"The Beatles (The White Album)", "The Beatles"},
                                                                  {
                                                                      "I Never Loved A Man the Way I Love You",
                                                                      "Aretha Franklin"
                                                                      },
                                                                  {
                                                                      "Modern Sounds in Country and Western Music",
                                                                      "Ray Charles"
                                                                      },
                                                                  {"Blue", "Joni Mitchell"},
                                                                  {"Tapestry", "Carole King"},
                                                                  {"Raising Hell", "Run-D.M.C."},
                                                                  {"Tommy", "The Who"},
                                                                  {"Led Zeppelin IV", "Led Zeppelin"},
                                                                  {
                                                                      "The Velvet Underground & Nico",
                                                                      "The Velvet Underground"
                                                                      },
                                                                  {"Appetite For Destruction", "Guns N Roses"},
                                                                  {"Paranoid", "Black Sabbath"},
                                                                  {"There's A Riot Goin' On", "Sly & The Family Stone"},
                                                                  {"Ziggy Stardust", "David Bowie"},
                                                                  {"Let It Bleed", "The Rolling Stones"},
                                                                  {"Bringing It All Back Home", "Bob Dylan"},
                                                                  {"Goodbye Yellow Brick Road", "Elton John"},
                                                                  {"Saturday Night Fever Soundtrack", "Various Artists"},
                                                                  {"Ten", "Pearl Jam"},
                                                                  {"Led Zeppelin I", "Led Zeppelin"},
                                                                  {"The Doors", "The Doors"},
                                                                  {"Superfly", "Curtis Mayfield"},
                                                                  {"The Miseducation of Lauryn Hill", "Lauryn Hill"},
                                                                  {"Back In Black", "AC/DC"},
                                                                  {"Born in the USA", "Bruce Springsteen"},
                                                                  {"Licensed to Ill", "Beastie Boys"},
                                                                  {"Never Mind the Bollocks", "The Sex Pistols"},
                                                                  {"Talking Book", "Stevie Wonder"},
                                                                  {"Lady Soul", "Aretha Franklin"},
                                                                  {"Sign 'O' The Times", "Prince"},
                                                                  {"The Ramones", "The Ramones"},
                                                                  {"Otis Blue", "Otis Redding"},
                                                                  {"Straight Outta Compton", "N.W.A."},
                                                                  {"Moondance", "Van Morrison"},
                                                                  {"After the Goldrush", "Neil Young"},
                                                                  {"The Chronic", "Dr. Dre"},
                                                                  {"The Wall", "Pink Floyd"},
                                                                  {"Hotel California", "The Eagles"},
                                                                  {"Van Halen", "Van Halen"},
                                                                  {"Electric Ladyland", "Jimi Hendrix"},
                                                                  {"Ok Computer", "Radiohead"},
                                                                  {"Automatic for the People", "R.E.M."},
                                                                  {"Blood On the Tracks", "Bob Dylan"},
                                                                  {"Bridge Over Troubled Water", "Simon & Garfunkel"},
                                                                  {"Murmur", "R.E.M."},
                                                                  {"Like A Virgin", "Madonna"},
                                                                  {"A Hard Day's Night", "The Beatles"},
                                                                  {"Off the Wall", "Michael Jackson"},
                                                                  {"Achtung Baby", "U2"},
                                                                  {"The Band", "The Band"},
                                                                  {"Stand!", "Sly & The Family Stone"},
                                                                  {"From Elvis In Memphis", "Elvis Presely"},
                                                                  {"Metallica (The Black Album)", "Metallica"},
                                                                  {"Sticky Fingers", "The Rolling Stones"},
                                                                  {"Synchronicity", "The Police"},
                                                                  {"Paul's Boutique", "Beastie Boys"},
                                                                  {"Astral Weeks", "Van Morrison"},
                                                                  {"Number Of the Beast", "Iron Maiden"},
                                                                  {"Machine Head", "Deep Purple"},
                                                                  {"Surrealistic Pillow", "Jefferson Airplane"},
                                                                  {"Master Of Puppets", "Metallica"},
                                                                  {"The Clash", "The Clash"},
                                                                  {"Remain In Light", "Talking Heads"},
                                                                  {"Plastic Ono Band", "John Lennon"},
                                                                  {"Black Sabbath", "Black Sabbath"},
                                                                  {"3 Feet High and Rising", "De La Soul"},
                                                                  {"Catch A Fire", "Bob Marley & The Wailers"},
                                                                  {"The Queen Is Dead", "The Smiths"},
                                                                  {"The \"Chirping\" Crickets", "Buddy Holly"},
                                                                  {"Live At Leeds", "The Who"},
                                                                  {"Paid In Full", "Eric B. & Rakim"},
                                                                  {"Music From Big Pink", "The Band"},
                                                                  {"Fullfillingness' First Finale", "Stevie Wonder"},
                                                                  {"Disraeli Gears", "Cream"},
                                                                  {"Axis Bold As Love", "Jimi Hendrix "},
                                                              };

        public static Dictionary<string, string> Films = new Dictionary<string, string>
                                                             {
                                                                 {"The Godfather", "Francis Ford Coppola"},
                                                                 {"Citizen Kane", "Orson Welles"},
                                                                 {"Casablanca", "Michael Curtiz"},
                                                                 {"Gone With the Wind", "Victor Fleming"},
                                                                 {"Seven Samurai", "Akira Kurosawa"},
                                                                 {"Wizard of Oz", "Victor Fleming"},
                                                                 {"On the Waterfront", "Elia Kazan"},
                                                                 {"The Bridge on the River Kwai", "David Lean"},
                                                                 {"Rules Of The Game", "Jean Renoir"},
                                                                 {"The Godfather Part II", "Francis Ford Coppola"},
                                                                 {"Lawrence of Arabia", "David Lean"},
                                                                 {"It's A Wonderful Life", "Frank Capra"},
                                                                 {"Schindler's List", "Steven Spielberg"},
                                                                 {"To Kill A Mockingbird", "Robert Mulligan"},
                                                                 {"Star Wars", "George Lucas"},
                                                                 {"La Strada", "Federico Fellini"},
                                                                 {"Psycho", "Alfred Hitchcock"},
                                                                 {"Sunset Boulevard", "Billy Wilder"},
                                                                 {"La Dolce Vita", "Federico Fellini"},
                                                                 {"Wild Strawberries", "Ingmar Bergman"},
                                                                 {"Singin' in the Rain", "Gene Kelly"},
                                                                 {"Diabolique", "Henri-Georges Clouzot"},
                                                                 {"Strangelove", "Stanley Kubrick"},
                                                                 {"Smith Goes to Washington", "Frank Capra"},
                                                                 {"Apocalypse Now", "Francis Ford Coppola"},
                                                                 {"Once Upon a Time in the West", "Sergio Leone"},
                                                                 {"The Leopard", "Luchino Visconti"},
                                                                 {"Ikiru", "Akira Kurosawa"},
                                                                 {"The Good, the Bad and the Ugly", "Sergio Leone"},
                                                                 {"Vertigo", "Alfred Hitchcock"},
                                                                 {"Fantasia", "Walt Disney"},
                                                                 {"One Flew Over the Cuckoo's Nest", "Milos Forman"},
                                                                 {"Some Like it Hot", "Billy Wilder"},
                                                                 {"Peeping Tom", "Michael Powell"},
                                                                 {"2001: A Space Odyssey", "Stanley Kubrick"},
                                                                 {"Empire Strikes Back", "Irvin Kershner"},
                                                                 {"The Graduate", "Mike Nichols"},
                                                                 {"Andrei Rublev", "Andrei Tarkovsky"},
                                                                 {"The African Queen", "John Huston"},
                                                                 {"Chinatown", "Roman Polanski"},
                                                                 {"All About Eve", "Joseph L Mankiewicz"},
                                                                 {"The Grapes of Wrath", "John Ford"},
                                                                 {"8 1/2", "Federico Fellini"},
                                                                 {"North by Northwest", "Alfred Hitchcock"},
                                                                 {"Jaws", "Steven Spielberg"},
                                                                 {"The Maltese Falcon", "John Huston"},
                                                                 {"A Clockwork Orange", "Stanley Kubrick"},
                                                                 {"the Extra-Terrestrial", "Steven Spielberg"},
                                                                 {"Taxi Driver", "Martin Scorsese"},
                                                                 {"City Lights", "Charlie Chaplin"},
                                                                 {"A Streetcar Named Desire", "Elia Kazan"},
                                                                 {"Tokyo Story", "Yasujiro Ozu"},
                                                                 {"The World of Apu", "Satyajit Ray"},
                                                                 {"It Happened One Night", "Frank Capra"},
                                                                 {"Rear Window", "Alfred Hitchcock"},
                                                                 {"Life of Oharu", "Kenji Mizoguchi"},
                                                                 {"Sunrise", "F.W. Murnau"},
                                                                 {"The Gold Rush", "Charlie Chaplin"},
                                                                 {"Ugestu Monogatari", "Kenji Mizoguchi"},
                                                                 {"Aparajito", "Satyajit Ray"},
                                                                 {"Rashamon", "Akira Kurosawa"},
                                                                 {"The Seventh Seal", "Ingmar Bergman"},
                                                                 {"Battleship Potemkin", "Sergei Eisenstein"},
                                                                 {"Pather Panchali", "Satyajit Ray"},
                                                                 {"M", "Fritz Lang"},
                                                                 {"The Deer Hunter", "Michael Cimino"},
                                                                 {"High Noon", "Fred Zinnemann"},
                                                                 {"The Silence of the Lambs", "Jonathan Demme"},
                                                                 {"Rocky", "John G. Avildsen"},
                                                                 {"Bonnie and Clyde", "Arthur Penn"},
                                                                 {"The Treasure of Sierra Madre", "John Huston"},
                                                                 {"Double Indemnity", "Billy Wilder"},
                                                                 {"The Philadelphia Story", "George Cukor"},
                                                                 {"Doctor Zhivago", "David Lean"},
                                                                 {"The Birth of a Nation", "D.W. Griffith"},
                                                                 {"Amadeus", "Milos Forman"},
                                                                 {"Passion of Joan of Arc", "Carl Theodor Dreyer"},
                                                                 {"Pulp Fiction", "Quentin Tarantino"},
                                                                 {"Duck Soup", "Leon McCarey"},
                                                                 {"Rebel Without a Cause", "Nicholas Ray"},
                                                                 {"Ben-Hur", "William Wyler"},
                                                                 {"Raiders of the Lost Ark", "Steven Spielberg"},
                                                                 {"Saving Private Ryan", "Steven Spielberg"},
                                                                 {"Patton", "Franklin J. Schaffner"},
                                                                 {"Aguirre, Wrath of God", "Werner Herzog"},
                                                                 {"The Bicycle Thief", "Vittorio De Sica"},
                                                                 {"Sansho the Bailiff", "Kenji Mizoguchi"},
                                                                 {"Modern Times", "Charlie Chaplin"},
                                                                 {"Platoon", "Oliver Stone"},
                                                                 {"King Kong", "Merian C. Cooper"},
                                                                 {"Cinema Paradisio", "Giuseppe Tornatore"},
                                                                 {"All Quiet on the Western Front", "Lewis Milestone"},
                                                                 {"The Children of Paradise", "Marcel Carne"},
                                                                 {
                                                                     "The Discreet Charm of the Bourgeoisie", "Luis Bunuel"
                                                                     },
                                                                 {"Annie Hall", "Woody Allen"},
                                                                 {
                                                                     "Lord of the Rings: The Return of the King",
                                                                     "Peter Jackson"
                                                                     },
                                                                 {"Cries and Whispers", "Ingmar Bergman"},
                                                                 {"Yojimbo", "Akira Kurosawa"},
                                                                 {"City of God", "Fernando Meirelles"},
                                                             };

        static DataHelper()
        {
            for (int i = 0; i < 100; i++)
            {
                var key = rnd.Next(50, 2000).ToString();
                Dates[key] = key;
            }
        }

        public static Dictionary<string, string> Dates = new Dictionary<string, string>();

        private static readonly Random Rnd = new Random();

        public static Dictionary<EThemes, Dictionary<string, string>> Dico = new Dictionary<EThemes, Dictionary<string, string>>
                                                                                 {
                                                                                     {EThemes.Books, Books},
                                                                                     {EThemes.Cinema, Films},
                                                                                     {EThemes.Geography, Capitals},
                                                                                     {EThemes.History, Dates},
                                                                                     {EThemes.Music, Albums},
                                                                                 };

        public static IEnumerable<KeyValuePair<string, string>> GetFourRandomLines(Dictionary<string, string> dictionary)
        {
            var indexes = new List<int>();

            int count = 0;
            int delta = dictionary.Count/4;
            var i = Rnd.Next(dictionary.Count);
            for (int j = 0; count < 4; j++)
            {
                var index = (i + (j) * delta);
                if (indexes.Contains(index)) continue;
                yield return dictionary.ElementAt(index%dictionary.Count);
                count++;
                indexes.Add(index);
            }
        }

        public static Random rnd = new Random();

        public static void SetQuestion(Question q, string text, params object[] answers)
        {
            q.text = text;
            int nb = answers.Length;
            var rndAnswers = new string[nb];
            var ii = new List<int> { 0, 1, 2, 3 };
            while (ii.Count != 0)
            {
                int index = rnd.Next(ii.Count);
                var x = ii[index];
                rndAnswers[nb - ii.Count] = answers[x].ToString();
                if (x == 0)
                    q.goodAnswer = (byte)(nb - ii.Count);
                ii.RemoveAt(index);
            }
            q.SetAnswers(rndAnswers);

        }

        public static void MakeInterestingQuestion(Question q, EThemes theme)
        {
            switch (theme)
            {
                case EThemes.Cinema:
                    var films = GetFourRandomLines(Films).ToArray();
                    SetQuestion(q, "Who has made the movie '" + films[0].Key + "' ?", films.Select(x => x.Value).ToArray());
                    break;
                case EThemes.Music:
                    var albums = GetFourRandomLines(Albums).ToArray();
                    SetQuestion(q, "Who has made the album '" + albums[0].Key + "' ?", albums.Select(x => x.Value).ToArray());
                    break;
                case EThemes.Books:
                    var books = GetFourRandomLines(Books).ToArray();
                    SetQuestion(q, "Who is the writer of '" + books[0].Key + "' ?", books.Select(x => x.Value).ToArray());
                    break;
                case EThemes.History:
                    var years = GetFourRandomLines(Dates).ToArray();
                    SetQuestion(q, "When did the battle of " + years[0].Key + " happen ?",
                                years.Select(x => x.Value).ToArray());
                    break;
                case EThemes.Geography:
                    var pairs = GetFourRandomLines(Capitals).ToArray();
                    SetQuestion(q, "What is the capital of " + pairs[0].Key + " ?", pairs.Select(x => x.Value).ToArray());
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
    }
}
